import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $http, $fn, $Lazy } = window
// ===================================================================== Lazy
const $time = $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:{},
		// 提交表单列表
		formData : [
			{ label: '操作时间',			name: 'date_range', 		full:true, 	required:true, type:'date-range'  },
		]
	}
	
	model = {}
	
	open = model => {
		this.modal.open({ formRef: this.formRef})
		this.model = model
		
		$time.then(f=>{
			this.formRef.setValue({ date_range: f.duration['1-0-12']() })
			
			this.formRef.submit()
		})
	}
	
	search = param => $http.submit(this,'ts-report-card/itemNum',{ param, isPull:true }).then(data=>this.setState({ data }))
	search = param => {
		let api = {
			44022: 'ts-report-card/itemNum',
			44021: 'ts-report-card/total',
			44033: 'ts-report-card/total'
		}
		$http.submit(this, api[this.model] ,{ param, isPull:true }).then(data=>this.setState({ data }))
	}
	
	render(){
		const { data } = this.state
		return FormModal.call(this,{
			title:'统计', 
			labelWidth:'s5', 
			width:600,
			okText:'搜索',
			onSubmit: ({ date_range }) => {
				const param = { start_time: date_range?.[0], end_time: date_range?.[1], result_model:this.model }
				this.search(param)
			},
			suffix: (
				<>
					{
						this.model === 44022 && (
							<dl className='f12 lh30 tbor1'>
								<dd>条码例数 : <span className='ml20'>{ $fn.val(data.spec_code) }</span></dd>
								<dd>标本项数 : <span className='ml20'>{ $fn.val(data.item_num) }</span></dd>
							</dl>
						)
					}
					{
						(this.model === 44021 ||this.model === 44033) && (
							<dl className='f12 lh30 tbor1'>
								<dd>蜡块数量 : <span className='ml20'>{ $fn.val(data.wax_block) }</span></dd>
								<dd>标本例数 : <span className='ml20'>{ $fn.val(data.spec_code) }</span></dd>
							</dl>
						)
					}
				</>
			)
		})
	}
}

export default Index